//
//  GoodsDetailsCell.m
//  BestPurchase
//
//  Created by ZSMAC on 2018/10/12.
//  Copyright © 2018年 张帅. All rights reserved.
//

#import "GoodsDetailsCell.h"
@interface GoodsDetailsCell ()
@property(nonatomic,strong)UIImageView * showImageView;
@property(nonatomic,strong)UILabel * contentLabel;
@property(nonatomic,assign)CGFloat imageProportion;//图片比例
@end
@implementation GoodsDetailsCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self uiConfigure];
    }
    return self;
}
- (void)uiConfigure {
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, SCREEN_WIDTH-30, 44)];
    self.contentLabel.font=Font(12);
    self.contentLabel.numberOfLines=0;
    [self addSubview: self.contentLabel];
    
    
    _showImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 5, SCREEN_WIDTH, 100)];
    _showImageView.image=[UIImage imageNamed:@"icon-1024"];
    [self.contentView addSubview:_showImageView];
    
}
- (void)setImageUrl:(NSString *)imageUrl {
    _imageUrl = imageUrl;
    _showImageView.hidden=NO;
    _contentLabel.hidden=YES;
    if (![_imageUrl containsString:@"&"]) {
        if (self.getCellHeight) {
            self.getCellHeight(_showImageView.bottom+10);
        }
        return;
    }
    NSRange range = [_cellModel.imageUrl rangeOfString:@"&"];//& 前面是 图片比例
    NSString *proportionStr = [_imageUrl substringWithRange:NSMakeRange(0, range.location)];
    _showImageView.height = [proportionStr floatValue] * _showImageView.width;
    if (self.getCellHeight) {
        self.getCellHeight(_showImageView.bottom+10);
    }
    NSString * newUrl = [_imageUrl substringFromIndex:proportionStr.length+1];
    UIImage * placeholderImage=[UIImage imageNamed:@"icon-1024"];//站位
    [_showImageView sd_setImageWithURL:[NSURL URLWithString:newUrl] placeholderImage:placeholderImage];
}
-(void)setCellModel:(GoodsDetailsCellModel *)cellModel {
    _cellModel=cellModel;
    _showImageView.hidden=YES;
    _contentLabel.hidden=YES;
    self.content=_cellModel.content;
    if (_cellModel.imageUrl.length>0 && _cellModel.imageUrl!=nil) {
        self.imageUrl=_cellModel.imageUrl;
    }
}
- (void)setContent:(NSString *)content {
    _content=content;
    _showImageView.hidden=YES;
    _contentLabel.hidden=NO;
    self.contentLabel.text=_content;
    if (_indexPath.row==0) {
        _contentLabel.font=[UIFont boldSystemFontOfSize:17];
        _contentLabel.textColor=[UIColor redColor];
    }else if (_indexPath.row==1) {
        _contentLabel.font=[UIFont boldSystemFontOfSize:18];
        _contentLabel.textColor=[UIColor blackColor];
    } else {
        _contentLabel.font=[UIFont systemFontOfSize:12];
        _contentLabel.textColor=MyRGB(153, 153, 153);
    }
  CGSize size = [_contentLabel sizeThatFits:CGSizeMake(_contentLabel.width, CGFLOAT_MAX)];
    if (size.height>_contentLabel.height) {
        _contentLabel.height=size.height;
    }
    if (self.getCellHeight) {
        self.getCellHeight(_contentLabel.bottom+10);
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
